package com.omesoft.hksnore.util.dialog;

/**
 * Created by Omesoft on 2017/2/21.
 */

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.omesoft.hksnore.R;


/**
 * 自定义进度对话框
 *
 * @author Omesoft
 *
 */
public class MyProgressBarDialog extends Dialog {
    private Context context;
    private ProgressBar progressBar;
    private TextView tv_titel, tv_content;
    private View view;

    public MyProgressBarDialog(Context context) {
        super(context, R.style.myDialog);
        this.context = context;
        // 加载布局文件
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.my_dialog_progressbar, null);
        progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        tv_titel = (TextView) view.findViewById(R.id.dialog_text_title);
        tv_content = (TextView) view.findViewById(R.id.dialog_text_content);
        // 给图片添加动态效果
        Animation anim = AnimationUtils.loadAnimation(context, R.anim.monitor_enteralpha);
        view.setAnimation(anim);
        setCanceledOnTouchOutside(false);
        // dialog添加视图
        setContentView(view);
        setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                // TODO Auto-generated method stub
                if (keyCode == KeyEvent.KEYCODE_BACK)
                    return true;
                else
                    return false;
            }
        });

    }

    public void setMsg(String msg) {
        if (tv_titel != null) {
            tv_titel.setText(msg);
        }
    }

    public void setMsg(int msgId) {
        if (tv_titel != null) {
            tv_titel.setText(msgId);
        }
    }

    public void setFinishText(int title, int content) {
        if (tv_titel != null && tv_content != null) {
            progressBar.setVisibility(View.GONE);
            tv_titel.setText(title);
            tv_content.setText(content);
            tv_content.setVisibility(View.VISIBLE);
        }
    }

    public void setFinishText(String title, String content) {
        if (tv_titel != null && tv_content != null) {
            progressBar.setVisibility(View.GONE);
            tv_titel.setText(title);
            tv_content.setText(content);
            tv_content.setVisibility(View.VISIBLE);
        }
    }

    public void dismiss() {
        super.dismiss();
    }

}
